import cv2 as cv
import numpy as np

image = cv.imread('/Users/apple/Desktop/data/lena.jpg')
image = cv.pyrDown(image)
cv.imshow('Original image', image)


# RGB->R,G,B
(B, G, R) = cv.split(image)
cv.imshow('Blue image', B)
cv.imshow('Green image', G)
cv.imshow('Red image', G)


# 把RGB的灰度单通道叠加成为三通道
'''
zeros = np.zeros(image.shape[:2], dtype = "uint8")
cv.imshow('Blue image', cv.merge([B, zeros, zeros]))
cv.imshow('Green image', cv.merge([ zeros, G, zeros]))
cv.imshow('Red image', cv.merge([zeros, zeros, R]))
'''


# RGB->HSI
hsvImg = cv.cvtColor(image, cv.COLOR_BGR2HSV)
hsvChannels = cv.split(hsvImg)

cv.imshow('Hue image', hsvChannels[0])
cv.imshow('Saturation image', hsvChannels[1])
cv.imshow('Value image', hsvChannels[2])

cv.waitKey()
cv.destroyAllWindows()
